import axios from './axios'

export async function category(type) {
    const cache = sessionStorage.getItem(`category${type}`)
    if (cache) {
        return JSON.parse(cache)
    } else {
        const res = await axios.get(`/category/${type}`)
        if (res) {
            sessionStorage.setItem(`category${type}`, JSON.stringify(res.data))
            return res.data
        } else {
            return []
        }
    }
}

export async function department() {
    const cache = sessionStorage.getItem('department')
    if (cache) {
        return JSON.parse(cache)
    } else {
        const res = await axios.get('/department')
        if (res) {
            sessionStorage.setItem('department', JSON.stringify(res.data))
            return res.data
        } else {
            return []
        }
    }
}

export async function state() {
    const cache = sessionStorage.getItem('state')
    if (cache) {
        return JSON.parse(cache)
    } else {
        const res = await axios.get('/state')
        if (res) {
            sessionStorage.setItem('state', JSON.stringify(res.data))
            return res.data
        } else {
            return []
        }
    }
}
